package com.becca.cake.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Encoder;

/**
 * MD5加密
 * @author hejinguo
 * @version $Id: MD5Util.java, v 0.1 2013-12-2 上午09:13:54
 */
public class MD5Util {
    /**
     * MD5加密
     * @param msg
     * @return
     */
    public static String getMD5Password(String msg) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

        byte[] b1 = msg.getBytes();
        byte[] b2 = md.digest(b1);

        //把字节数组编码成字符串
        BASE64Encoder encoder = new BASE64Encoder();

        String password = encoder.encode(b2);
        return password;
    }

    public static void main(String[] args) {
        System.out.println(getMD5Password("111111"));
    }
}
